exec(open('init_path.py').read())
exec((P_Lib/'GasStation.py').read_text())

fuels = ['e5','e10','diesel']

for fuel in fuels:
    
    # split the file into ~/data
    def split_dta_by_stid(s):
        stid = s.StID.values[0]
        f = P / (str(stid)+'_'+fuel+'.dta')
        s.to_stata(f, write_index=False)
        return None

    ## OIL  

    oil_price_freq = '5min'
    shock_thld = 'P90'
    res_thld = 5
    fname = '_'.join([fuel,'shock', oil_price_freq, shock_thld, 'response', str(res_thld)+'min', version]) + '.dta'
    f = P_GS_Data / 'break_oil' / fname
    df = read_stata(f)

    P = P_GS_Data / 'break_oil' / 'Separate'
    df.groupby('StID').apply(split_dta_by_stid);

    ## WEATHER

    weather_type = 'temp'
    shock_type = 'neg'
    shock_col = {'neg':'ShockNeg','pos':'ShockPos','any':'ShockAny'}[shock_type]
    #fuel = 'e5'
    res_thld = 10
    fname = '_'.join([weather_type, shock_type, ('wi'+str(res_thld)+'m'), fuel]) + '.dta'

    f = P_GS_Data / 'break_weather' / fname
    df = read_stata(f)
    P = P_GS_Data / 'break_weather' / 'Separate'
    df.groupby('StID').apply(split_dta_by_stid);

    ## PCCOUNT

    fname = 'weekly_nPCCount_'+fuel+'.dta'

    f = P_GS_Data / 'break_pccount' / fname
    df = read_stata(f)
    P = P_GS_Data / 'break_pccount' / 'Separate'
    df.groupby('StID').apply(split_dta_by_stid);

    ## PCRESPONSE 

    fname = 'weekly_nPCResponse_'+fuel+'.dta'
    f = P_GS_Data / 'break_pcresponse' / fname
    df = read_stata(f)
    P = P_GS_Data / 'break_pcresponse' / 'Separate'
    df.groupby('StID').apply(split_dta_by_stid);

